package written.w20240908xiaohongshu.q2;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Main
 *
 * @Author : Ruoyu Wang
 * @DateTime : 2024/9/8 15:10
 */

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        long[] counts = new long[n];
        for (int i = 0; i < n; i++) {
            counts[i] = (long) (i + 1) * (n - i);
        }
        Arrays.sort(a);
        Long[] counts_sorted = new Long[n];
        for (int i = 0; i < n; i++) {
            counts_sorted[i] = counts[i];
        }
        Arrays.sort(counts_sorted, (x, y) -> Long.compare(y, x));
        long result = 0;
        for (int i = 0; i < n; i++) {
            result += a[i] * counts_sorted[i];
        }
        System.out.println(result);
        scanner.close();
    }
}
